{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {
    "dotnet_interactive": {
     "language": "csharp"
    },
    "polyglot_notebook": {
     "kernelName": "csharp"
    }
   },
   "source": [
    "# HttpClient 测试"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "dotnet_interactive": {
     "language": "csharp"
    },
    "polyglot_notebook": {
     "kernelName": "csharp"
    },
    "vscode": {
     "languageId": "polyglot-notebook"
    }
   },
   "source": [
    "## 1、引用项目Dll"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {
    "dotnet_interactive": {
     "language": "csharp"
    },
    "polyglot_notebook": {
     "kernelName": "csharp"
    },
    "vscode": {
     "languageId": "polyglot-notebook"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1.0项目管理.dib\n",
      "1.1.概述.ipynb\n",
      "1.2.使用准则.ipynb\n",
      "1.3.0.基础使用.管理客户端.ipynb\n",
      "1.3.1.基础使用.发送请求.ipynb\n",
      "1.3.2.基础使用.使用请求体.ipynb\n",
      "1.3.3.基础使用.处理响应.ipynb\n",
      "1.3.4.基础使用.处理错误.ipynb\n",
      "1.3.5.基础使用.使用代理.ipynb\n",
      "1.3.6.基础使用.使用Json.ipynb\n",
      "1.3.7.基础使用.使用Cookie.ipynb\n",
      "1.4.0.高级使用.概述.ipynb\n",
      "1.4.1.高级使用.初始化.ipynb\n",
      "1.4.2.高级使用.连接池.ipynb\n",
      "1.4.3.高级使用.重复使用.ipynb\n",
      "1.4.4.高级使用.使用管道.ipynb\n",
      "1.4.5.高级使用.类型化客户端.ipynb\n",
      "1.4.6..高级使用.工厂模式.ipynb\n",
      "1.4.7.高级使用.Polly.ipynb\n",
      "1.5.总结.ipynb\n",
      "1.6.测试.ipynb\n",
      "2.1.内核中的各种路径.ipynb\n",
      "Assets\n",
      "Publish\n",
      "学习.ps1\n",
      "说明.md\n",
      "\r\n"
     ]
    }
   ],
   "source": [
    "//引用项目\n",
    "#r \"./Publish/HttpClientStudy.Core/HttpClientStudy.Core.dll\"\n",
    "\n",
    "//执行C#工具方法\n",
    "using HttpClientStudy.Core.Utilities;\n",
    "\n",
    "\n",
    "var result = AppUtility.RunCmd(\"ls\");\n",
    "Console.WriteLine(result);"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 2、Powershell 管理项目"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {
    "dotnet_interactive": {
     "language": "pwsh"
    },
    "polyglot_notebook": {
     "kernelName": "pwsh"
    },
    "vscode": {
     "languageId": "polyglot-notebook"
    }
   },
   "outputs": [],
   "source": [
    "#启动已发布的WebApi项目\n",
    "Start-Process -FilePath dotnet -ArgumentList \".\\Publish\\HttpClientStudy.WebApp\\HttpClientStudy.WebApp.dll\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {
    "dotnet_interactive": {
     "language": "pwsh"
    },
    "polyglot_notebook": {
     "kernelName": "pwsh"
    },
    "vscode": {
     "languageId": "polyglot-notebook"
    }
   },
   "outputs": [],
   "source": [
    "# 编译并启动WebApi项目\n",
    "Start-Process -FilePath dotnet -ArgumentList \"run --project ..\\HttpClientStudy.WebApp\\HttpClientStudy.WebApp.csproj\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "metadata": {
    "dotnet_interactive": {
     "language": "pwsh"
    },
    "polyglot_notebook": {
     "kernelName": "pwsh"
    },
    "vscode": {
     "languageId": "polyglot-notebook"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "进程没有找到，可能已经关闭\r\n"
     ]
    },
    {
     "ename": "Error",
     "evalue": "Command failed: SubmitCode: # 关闭项目进程 ...",
     "output_type": "error",
     "traceback": [
      "Command failed: SubmitCode: # 关闭项目进程 ..."
     ]
    }
   ],
   "source": [
    "# 关闭项目进程\n",
    "$WebAppProcName =\"HttpClientStudy.WebApp\";\n",
    "$WebAppProc = Get-Process $WebAppProcName -ErrorAction Ignore\n",
    "if($null -eq $WebAppProc)\n",
    "{\n",
    "    Write-Host \"进程没有找到，可能已经关闭\"\n",
    "}\n",
    "else {\n",
    "    $WebAppProc.Kill();\n",
    "    Write-Host \"$WebAppProcName 进程已退出\"\n",
    "}"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 3、C#类库管理项目"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {
    "dotnet_interactive": {
     "language": "csharp"
    },
    "polyglot_notebook": {
     "kernelName": "csharp"
    },
    "vscode": {
     "languageId": "polyglot-notebook"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "c:\\Users\\ruyu\\Desktop\\HttpClientStudy\\Docs\\Publish\\HttpClientStudy.WebApp\\HttpClientStudy.WebApp.exe"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "程序[c:\\Users\\ruyu\\Desktop\\HttpClientStudy\\Docs\\Publish\\HttpClientStudy.WebApp\\HttpClientStudy.WebApp.exe]已在新的命令行窗口执行。如果未出现新命令行窗口，可能是程序错误造成窗口闪现！\r\n"
     ]
    }
   ],
   "source": [
    "//启动已发布的WebApi项目\n",
    "#r \"./Publish/HttpClientStudy.Core/HttpClientStudy.Core.dll\"\n",
    "\n",
    "{\n",
    "    var file = System.IO.Path.GetFullPath(\"./Publish/HttpClientStudy.WebApp/HttpClientStudy.WebApp.exe\",System.Environment.CurrentDirectory);\n",
    "\n",
    "    file.Display();\n",
    "    var message = HttpClientStudy.Core.Utilities.AppUtility.RunWebApiExeFile(file);\n",
    "\n",
    "    Console.WriteLine(message);\n",
    "}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {
    "dotnet_interactive": {
     "language": "csharp"
    },
    "polyglot_notebook": {
     "kernelName": "csharp"
    },
    "vscode": {
     "languageId": "polyglot-notebook"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "配置文件根目录：c:\\Users\\ruyu\\Desktop\\HttpClientStudy\\Docs\\Publish\\HttpClientStudy.Core\n",
      "WebApi程序[进程号：，进程名：]，已关闭！\n"
     ]
    }
   ],
   "source": [
    "//关闭项目进程\n",
    "#r \"./Publish/HttpClientStudy.Core/HttpClientStudy.Core.dll\"\n",
    "\n",
    "{\n",
    "    var message = HttpClientStudy.Core.Utilities.AppUtility.StopWebApiExeFile();\n",
    "    Console.WriteLine(message);\n",
    "}"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": ".NET (C#)",
   "language": "C#",
   "name": ".net-csharp"
  },
  "language_info": {
   "name": "python"
  },
  "polyglot_notebook": {
   "kernelInfo": {
    "defaultKernelName": "csharp",
    "items": [
     {
      "aliases": [],
      "name": "csharp"
     }
    ]
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
